import { useCoachStore } from "@/store/coach.ts";
import { ref } from "vue";
import { deleteCoachAPI } from "@/api/destribute.ts";
import { ElMessage } from "element-plus";

export default function useCoach() {
  const coachStore = useCoachStore()
  const dialog = ref()

  // 添加教练
  const handleAdd = () => {
    dialog.value.init({}, 1)
  }

  // 删除教练
  const deleteCoach = async (id) => {
    const res = await deleteCoachAPI(id)
    if (res.code === 0) {
      await coachStore.getCoachList()
      ElMessage({
        type: 'success',
        message: res.message
      })
    }
  }

  // 编辑教练
  const EditCoach = (row) => {
    dialog.value.init(row, 2)
  }

  return {
    dialog,
    coachStore,
    handleAdd,
    EditCoach,
    deleteCoach
  }
}
